<?php

require_once __DIR__."/../../library/mysql/ye_mysql.php";
require_once __DIR__."/../common/db.php";
class Report
{
    private  static $db = [
        'host'     => 'rm-uf6ss18k4r16xa9y9.mysql.rds.aliyuncs.com',
        'user'     => 'longmao',
        'pass'     => '@L8121a42ad8c5c',
        'charset'  => 'utf8',
        'port'     => 25686,
        'prefix'   => '',
    ];

    private static $db_test = [
        'host'     => '127.0.0.1',
        'user'     => 'root',
        'pass'     => 'lm123456',
        'charset'  => 'utf8',
        'port'     => 3306,
        'prefix'   => '',
    ];


    /**
     * @param $params
     * @return array
     * 查询list数据
     */
    public static function _list($params){
        if (empty($params['db']) || empty($params['table']) || empty($params['where']) || empty($params['db_type'])){
            return ["code"=>1,"msg"=>"缺少参数1"];
        }

        if (empty($params['field']) || empty($params['order']) || (empty($params['page']) && $params['page'] != 0 )  || empty($params['page_size'])){
            return ["code"=>1,"msg"=>"缺少参数2"];
        }

        if ($params['db_type'] = 1){
            $db = self::$db;
        }else{
            $db = self::$db_test;
        }

        $db['db'] = $params['db'];
        db::set_config($db);
        $data = db::_list($params['table'],$params['where'],$params['field'],$params['order'],$params['group'],$params['page'],$params['page_size']);
        return $data;
    }


    /**
     * @param $params
     * @return array
     * select 数据
     */
    public static function select($params){
        if (empty($params['db']) || empty($params['table']) || empty($params['where']) || empty($params['db_type']) || empty($params['field'])){
            return ["code"=>1,"msg"=>"缺少参数"];
        }

        if ($params['db_type'] = 1){
            $db = self::$db;
        }else{
            $db = self::$db_test;
        }

        $db['db'] = $params['db'];
        db::set_config($db);
        $data = db::select($params['table'],$params['where'],$params['field'],$params['order'],$params['group']);
        return $data;
    }


    /**
     * @param $params
     * @return array|bool|mixed|mysqli_result|resource|void|null
     * sql查询数据
     */
    public static function query($params){
        if (empty($params['db']) || empty($params['db_type']) || empty($params['sql'])){
            return ["code"=>1,"msg"=>"缺少参数"];
        }
        if ($params['db_type'] = 1){
            $db = self::$db;
        }else{
            $db = self::$db_test;
        }
        $db['db'] = $params['db'];
        db::set_config($db);
        $data = db::query($params['sql']);
        return $data;
    }
}